//
//  HCComModel.m
//  HelloCall
//
//  Created by WangYongpeng on 13-11-13.
//  Copyright (c) 2013年 HC. All rights reserved.
//

#import "HCComModel.h"

#import <set>
using namespace std;

typedef std::set< id<HCModelDataObserver> > NBGMObervers;

@interface HCComModel()
{
    NBGMObervers m_observers;
    BOOL m_notifySendEnable;
}
@end

@implementation HCComModel

- (id)init
{
    self = [super init];
    if (self != nil)
    {
        m_notifySendEnable = YES;
    }
    return self;
}

- (void)enableSendNotify:(BOOL)enabled
{
    m_notifySendEnable = enabled;
}

- (void)addObserver:(id <HCModelDataObserver>)observer
{
    assert(observer);
    m_observers.insert(observer);
}

- (void)removeObserver:(id <HCModelDataObserver>)observer
{
    assert(observer);
    m_observers.erase(observer);
}

- (void)sendDataUpdateEvent:(int)msgID
{
    if (m_notifySendEnable)
    {
        for (NBGMObervers::iterator it = m_observers.begin();
             it != m_observers.end();
             it++)
        {
            if ([*it respondsToSelector:@selector(dataUpdateByMsgID:)])
            {
                [*it dataUpdateByMsgID:msgID];
            }
        }
    }
    
}

@end
